package main

import "fmt"

//计算多个人的平均体脂
//实现完整的体脂计算器
//连续输入三人的姓名、性别、身高、体重、年龄信息
//计算每个人的BMI、体脂率
//输出：
//每个人的姓名、BMI、体脂率、建议
//总人数、平均体脂率

func main() {
	for {
		//提示要求
		giveUserTip()
		intSum++
		var strContinue string
		fmt.Scan(&strContinue)
		if strContinue == "N" {
			break
		}
	}
	if intSum > 0 {
		fmt.Printf("总共输入%d人的信息，%d人的体脂率平均值为:%f", intSum, intSum, floatTotalBodyFat/float64(intSum))
	} else {
		fmt.Printf("没有输入，退出程序")
	}
}

var floatTotalBodyFat float64 = 0.0
var intSum int = 0

func giveUserTip() {
	fmt.Println("请按照姓名，性别(男/女)，身高(米)，体重(公斤)，年龄信息(岁)的格式输入三个人的信息(信息用空格隔开)")
	getUserInfo()
	fmt.Println("是否继续录入？输入Y/N")
}

//获取输入的用户信息
func getUserInfo() {
	strName := ""
	strSex := "男"
	floatHeight := 1.0
	floatWeight := 50.0
	intAge := 11
	fmt.Scan(&strName, &strSex, &floatHeight, &floatWeight, &intAge)
	fmt.Printf("name:%s sex:%s Height:%f Weight:%f age:%d \n", strName, strSex, floatHeight, floatWeight, intAge)
	//计算体脂率
	floatBmi := floatWeight / (floatHeight * floatHeight)
	mapSex := map[string]int{
		"男": 1,
		"女": 0,
	}
	floatBodyFat := (1.2*floatBmi + 0.23*float64(intAge) - 5.4 - 10.8*float64(mapSex[strSex])) / 100
	fmt.Printf("%s 的体脂率为:%f ", strName, floatBodyFat)
	floatTotalBodyFat += floatBodyFat
	//计算出来体脂率后 根据不同的性别 执行不同的输出方法 避免出现过多的if影响代码的可读性
	if strSex == "男" {
		getMaleSuggestion(floatBodyFat, intAge)
	} else {
		getFeMaleSuggestion(floatBodyFat, intAge)
	}
}

//男生输出的建议
func getMaleSuggestion(floatBodyFat float64, intAge int) {
	strPrintInfo := ""
	switch {
	case intAge >= 18 && intAge <= 39:
		switch {
		case floatBodyFat > 0.0 && floatBodyFat <= 0.10:
			strPrintInfo = "你的体型属于偏瘦"
		case floatBodyFat > 0.1 && floatBodyFat <= 0.16:
			strPrintInfo = "你的体型属于正常"
		case floatBodyFat > 0.16 && floatBodyFat <= 0.21:
			strPrintInfo = "你的体型属于偏重"
		case floatBodyFat > 0.21 && floatBodyFat <= 0.26:
			strPrintInfo = "你的体型属于肥胖"
		case floatBodyFat > 0.26:
			strPrintInfo = "你的体型属于严重肥胖"
		default:
			strPrintInfo = "你的体脂率小于0，请核对输入的信息"
		}
	case intAge >= 40 && intAge <= 59:
		switch {
		case floatBodyFat > 0 && floatBodyFat <= 0.11:
			strPrintInfo = "你的体型属于偏瘦"
		case floatBodyFat > 0.11 && floatBodyFat <= 0.17:
			strPrintInfo = "你的体型属于正常"
		case floatBodyFat > 0.17 && floatBodyFat <= 0.22:
			strPrintInfo = "你的体型属于偏重"
		case floatBodyFat > 0.22 && floatBodyFat <= 0.27:
			strPrintInfo = "你的体型属于肥胖"
		case floatBodyFat > 0.27:
			strPrintInfo = "你的体型属于严重肥胖"
		default:
			strPrintInfo = "你的体脂率小于0，请核对输入的信息"
		}
	case intAge >= 60:
		switch {
		case floatBodyFat > 0 && floatBodyFat <= 0.13:
			strPrintInfo = "你的体型属于偏瘦"
		case floatBodyFat > 0.13 && floatBodyFat <= 0.19:
			strPrintInfo = "你的体型属于正常"
		case floatBodyFat > 0.19 && floatBodyFat <= 0.24:
			strPrintInfo = "你的体型属于偏重"
		case floatBodyFat > 0.24 && floatBodyFat <= 0.29:
			strPrintInfo = "你的体型属于肥胖"
		case floatBodyFat > 0.29:
			strPrintInfo = "你的体型属于严重肥胖"
		default:
			strPrintInfo = "你的体脂率小于0，请核对输入的信息"
		}
	default:
		strPrintInfo = "输入的年龄异常，请核对输入的信息"
	}
	fmt.Printf("%s \n", strPrintInfo)
}

//女生输出的建议
func getFeMaleSuggestion(floatBodyFat float64, intAge int) {
	strPrintInfo := ""
	switch {
	case intAge >= 18 && intAge <= 39:
		switch {
		case floatBodyFat > 0 && floatBodyFat <= 0.2:
			strPrintInfo = "你的体型属于偏瘦"
		case floatBodyFat > 0.2 && floatBodyFat <= 0.27:
			strPrintInfo = "你的体型属于正常"
		case floatBodyFat > 0.27 && floatBodyFat <= 0.34:
			strPrintInfo = "你的体型属于偏重"
		case floatBodyFat > 0.34 && floatBodyFat <= 0.39:
			strPrintInfo = "你的体型属于肥胖"
		case floatBodyFat > 0.39:
			strPrintInfo = "你的体型属于严重肥胖"
		default:
			strPrintInfo = "你的体脂率小于0，请核对输入的信息"
		}
	case intAge >= 40 && intAge <= 59:
		switch {
		case floatBodyFat > 0 && floatBodyFat <= 0.21:
			strPrintInfo = "你的体型属于偏瘦"
		case floatBodyFat > 0.21 && floatBodyFat <= 0.28:
			strPrintInfo = "你的体型属于正常"
		case floatBodyFat > 0.28 && floatBodyFat <= 0.35:
			strPrintInfo = "你的体型属于偏重"
		case floatBodyFat > 0.35 && floatBodyFat <= 0.40:
			strPrintInfo = "你的体型属于肥胖"
		case floatBodyFat > 0.40:
			strPrintInfo = "你的体型属于严重肥胖"
		default:
			strPrintInfo = "你的体脂率小于0，请核对输入的信息"
		}
	case intAge >= 60:
		switch {
		case floatBodyFat > 0 && floatBodyFat <= 0.22:
			strPrintInfo = "你的体型属于偏瘦"
		case floatBodyFat > 0.22 && floatBodyFat <= 0.2:
			strPrintInfo = "你的体型属于正常"
		case floatBodyFat > 0.29 && floatBodyFat <= 0.36:
			strPrintInfo = "你的体型属于偏重"
		case floatBodyFat > 0.36 && floatBodyFat <= 0.41:
			strPrintInfo = "你的体型属于肥胖"
		case floatBodyFat > 0.41:
			strPrintInfo = "你的体型属于严重肥胖"
		default:
			strPrintInfo = "你的体脂率小于0，请核对输入的信息"
		}
	default:
		strPrintInfo = "输入的年龄异常，请核对输入的信息"
	}
	fmt.Printf("%s \n", strPrintInfo)
}
